scanner: return stream read errors to callers - #295
Open
SantanDon wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Prevent Flex stream read errors from terminating the process inside libconfig.
Flex's default
YY_INPUTcallsYY_FATAL_ERROR("input in flex scanner failed")whenfread()fails for a reason other thanEINTR. That is reasonable for a standalone scanner, but not for a library API: the caller never gets a chance to handle the error.This overrides the scanner input hook so it keeps the existing
EINTRretry behavior, but leaves other stream read failures for the scanner's EOF rule to report asTOK_ERROR. The existing parser cleanup path then unwinds includes andconfig_read*()returnsCONFIG_FALSEwith the usual error fields populated.No public API or ABI changes are involved.
Reproduction
On POSIX, this public issue #292 reproducer is enough:
A directory can be opened as a stream, but reading it fails. On current
master(e485a729d2cf27321a560a61af0816b123337d00), the process exits from the generated scanner with:With this change, the call returns normally:
The same process-fatal scanner behavior was also reported historically in #56.
Tests
IncludeReadError, which verifiesconfig_read_string(..., "@include \".\"")returns false instead of terminating the test process.config_read_file()smoke test passes under ASan/UBSan.git diff --checkis clean.Fixes #292.